#include <iostream>
#include "../comm/httplib.h"
#include "oj_control.hpp"

int main()
{
    httplib::Server svr;
    ns_control::Control _ctrl;


    svr.Get("/questions", [&_ctrl](const httplib::Request& req, httplib::Response& resp){
        std::string html;
        _ctrl.AllQuestions(&html); // 获取所有题目网页
        resp.set_content(html, "text/html; charset=utf-8");
    });

    svr.Get(R"(/question/(\d+))", [&_ctrl](const httplib::Request& req, httplib::Response& resp){
        std::string html;
        _ctrl.OneQuestion(req.matches[1], &html); // 获取所有题目网页
        resp.set_content(html, "text/html; charset=utf-8");
    });

    svr.Post(R"(/judge/(\d+))", [&_ctrl](const httplib::Request& req, httplib::Response& resp){
        std::string out;
        std::string id = std::string(req.matches[1]);
        _ctrl.Judge(id, req.body, &out);
        resp.set_content(out, "application/json;charset=utf-8");
    });

    svr.set_base_dir("./wwwroot");


    svr.listen("0.0.0.0", 8080);

    return 0;
}